Feature Extraction & Image Processing,
M. S. Nixon and A. S. Aguado
Elsevier/ Butterworth Heinmann, 2nd Edition 2007
This worksheet is the companion to Chapter 1 and is an introduction. It is the source of Section 1.5.2 Hello Mathcad, Hello Images. The worksheet follows the text directly and allows you to process basic images.
Pixels are addressed in row-column format. Using x for the horizontal axis (a column count), and y for the vertical axis (a row count) then picture points are addressed as picy,x. The origin is at co-ordinates y = 0 and x = 0, so the point pic2,2 is on the third row and third column; the point pic3,2 is on the fourth row, at the third column. Let's print them:
We can view the matrix as a surface plot from the Graphics menu, as a surface (or function), or as an image.
Figure 1.12(b). Note that interpolation gives
the slope at the edges of the square. We'll
only use this format occasionally.
Note that since the origin is at co-ordinates (0,0), the top left hand corner of the image. For this image which has 8 rows and 8 columns, the bottom right hand point is pic7,7. The number of rows and the number of columns can be derived by the Mathcad rows and columns functions (Code 1.1):
We can define a subroutine to invert the image, by subtracting the value for each point from the maximum value of the points in the image. The maximum is given by the max function:
To access image points, we will need x and y co-ordinates. The columns index x starts at the origin (0) and addresses points up to the number of columns - 1. The index y does the rows. The new picture new_pic is then calculated by the routine (Code 1.2):
The addition process can be formulated as a function, which requires an input picture, and a value, as arguments. The result is a new picture where each pixel is the corresponding point in the input picture plus the value. The function add_value is then (Code 1.3):
We usually need to demonstrate algorithms on real images which are much bigger than this synthetic one. To do this, we need to read a Windows bitmap image using the READBMP command. Let's read in the image of a face.
Mathcad's picture facility gives us a much faster way of viewing images, simply because they are displayed as a picture, rather than as a specially arranged surface plot. This way, you don't have to wait for the image to be recalculated when you zoom up and down the worksheet. The only problem is that if you apply the algorithms to a picture a different size and then view it as the same picture, you'll need to re-size the picture (click on the background, drag the cursor over the picture and then make it bigger - like in Word). If you want to see what's been sent to the picture, just click on it and the variables will show up.
Sometimes, it's prudent to write big images as bitmaps using the WRITEBMP command and view them with a bitmap viewer.
Let's do some simple processing. First, let's make the image brighter:
Finally, let's generate the banded image for the Mach band effect. We need to create an image, so let's assign the image face to an image mach